<?php
/*
 * Tạo Support Product widget
* */
class Bottombox_clip extends WP_Widget
{
	
	//Khởi tạo contructor của 1 lớp
	function Bottombox_clip()
	{
		parent::WP_Widget('Bottombox_clip_Widget',
				esc_attr(__('Footer video clip',THMENAME)),
				array('description' => esc_attr(__('Thả vào Box 1,Box 2,Box 3 footer.',THEMENAME))));

	}

	function widget( $args, $instance ) // hien thi noi dung widget
	{
		global $currency;
		extract($args);
		$title = apply_filters( 'widget_title',
				empty($instance['title']) ? '' : $instance['title'],
				$instance, $this->id_base);

		$showposts = apply_filters( 'widget_text',
				$instance['showposts'], $instance );

		$selected = apply_filters( 'widget_text',
				$instance['selected'], $instance );
		$todisplay = apply_filters( 'widget_text',
				$instance['todisplay'], $instance );

		?>
		 <div class="moduletable">
					<h3><?php echo $title;?></h3>
					<div class="ja-sidenews-list clearfix">
					<?php 
					$duan = new WP_Query(array('post_type' => 'tin-tuc','orderby'=>'modified','order'=>'DESC','showposts' => $showposts,'tax_query' => array(array('taxonomy'=>'tin-tuc-bds','field'=>'slug','terms'=>'video-clip-bds'))));
					
					if($duan->have_posts()):
					while ($duan->have_posts()):
						$duan->the_post();
						
						if($todisplay==0)
							$todisplay=1;						
						include TEMPLATEPATH.'/includes/widgets/footer-layout'.$todisplay.'.php';
					?>
					
			  		<?php endwhile;?>
			  		<?php 			  		
			  		endif;
			  		
			  		$duan = '';
			  		?>
  				 </div>		
 			</div>			
		<?php		
	}

	function update( $new_instance, $old_instance ) 
	{
		$instance = $old_instance;
				
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['showposts'] = strip_tags($new_instance['showposts']);		
		$instance['selected'] = strip_tags($new_instance['selected']);	
		$instance['todisplay'] = strip_tags($new_instance['todisplay']);
			
		return $instance;
	}

	function form( $instance ) 
	{
		$instance = wp_parse_args( (array) $instance, 
			array( 'title' => '','todisplay' => '', 'showposts' => '','selected'=>'' ) );
		$title = strip_tags($instance['title']);
		$showposts = strip_tags($instance['showposts']);
		$todisplay = strip_tags($instance['todisplay']);
		$selected = strip_tags($instance['selected']);
?>
		<p>
			<label for="<?php echo $this->get_field_id('title'); ?>">
				<?php echo  __('Tiêu đề:'); ?> </label>
			<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" 
				name="<?php echo $this->get_field_name('title'); ?>" type="text" 
				value="<?php if($title) echo  esc_attr($title);?>" />
		</p>
	
		<p>
			<label for="<?php echo $this->get_field_id('showposts'); ?>">
				<?php _e('Showposts:'); ?> </label>
			<input class="widefat" id="<?php echo $this->get_field_id('showposts'); ?>" 
				name="<?php echo $this->get_field_name('showposts'); ?>" type="text" 
				value="<?php if($showposts) echo  esc_attr($showposts); else echo '5';?>" />
		</p>
		
		<p style="display: none;">
			<label for="<?php echo $this->get_field_id('category'); ?>">
				<?php echo __('Loại dự án:',THEMENAME); ?> </label>						
				
				<select class="widefat" id="<?php echo $this->get_field_id('selected'); ?>" 
					name="<?php echo $this->get_field_name('selected'); ?>">
					<option value=""><?php echo __('Mặc định',THEMENAME);?></option>
					<option <?php if($selected=='can-ban') echo 'selected="selected"';?> value="<?php echo 'can-ban';?>"><?php echo __('Cần bán',THEMENAME);?></option>
					<option <?php if($selected=='cho-thue') echo 'selected="selected"';?> value="<?php echo 'cho-thue';?>"><?php echo __('Cho thuê',THEMENAME);?></option>
					
				</select>
				
		</p>
		
		<p>
			<label for="<?php echo $this->get_field_id('todisplay'); ?>">
				<?php echo __('Chọn hiển thị:',THEMENAME); ?> </label>						
				
				<select class="widefat" id="<?php echo $this->get_field_id('todisplay'); ?>" 
					name="<?php echo $this->get_field_name('todisplay'); ?>">
					<option value="0"><?php echo __('Mặc định',THEMENAME);?></option>
					<option <?php if($todisplay=='1') echo 'selected="selected"';?> value="1"><?php echo __('Kiểu 1',THEMENAME);?></option>
					<option <?php if($todisplay=='2') echo 'selected="selected"';?> value="2"><?php echo __('Kiểu 2 không thumb',THEMENAME);?></option>
					<option <?php if($todisplay=='3') echo 'selected="selected"';?> value="3"><?php echo __('Kiểu 3 Tiêu đề',THEMENAME);?></option>
					
				</select>
				
		</p>
		
<?php
	}
}
// End Support Product widget

register_widget('Bottombox_clip');

//===========================================================================================================================


// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++